package com.ruoyi.web.controller.system;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Label;
import com.ruoyi.system.domain.Tabs;
import com.ruoyi.system.service.ILabelService;

/**
 * 标签查询Controller
 * 
 * @author ruoyi
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/system/label")
public class LabelController extends BaseController
{
    @Autowired
    private ILabelService labelService;
    
    @GetMapping("/tagsList")
    public AjaxResult tagsList(Tabs tabs)
    {
    	return success(labelService.selectArticleLabel(tabs));
    }

    /**
     * 查询标签页
     */
//  @PreAuthorize("@ss.hasPermi('system:label:list')")
    @GetMapping("/labellist")
    public TableDataInfo labellist(Label label)
    {
    	startPage();
        List<Tabs> list = labelService.selectLabelArticleCounts(label);
        return getDataTable(list);
    }

    /**
     * 查询标签查询列表(不分页)
     */
//    @PreAuthorize("@ss.hasPermi('system:label:list')")
    @GetMapping("/listLabel")
    public AjaxResult listLabel(Label label)
    {
        return success(labelService.selectLabelList(label));
    }
    
    /**
     * 查询标签查询列表
     */
//    @PreAuthorize("@ss.hasPermi('system:label:list')")
    @GetMapping("/list")
    public TableDataInfo list(Label label)
    {
        startPage();
        List<Label> list = labelService.selectLabelList(label);
        return getDataTable(list);
    }

    /**
     * 导出标签查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:label:export')")
    @Log(title = "标签查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Label label)
    {
        List<Label> list = labelService.selectLabelList(label);
        ExcelUtil<Label> util = new ExcelUtil<Label>(Label.class);
        util.exportExcel(response, list, "标签查询数据");
    }

    /**
     * 获取标签查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:label:query')")
    @GetMapping(value = "/{labelId}")
    public AjaxResult getInfo(@PathVariable("labelId") Long labelId)
    {
        return success(labelService.selectLabelByLabelId(labelId));
    }

    /**
     * 新增标签查询
     */
    @PreAuthorize("@ss.hasPermi('system:label:add')")
    @Log(title = "标签查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Label label)
    {
        return toAjax(labelService.insertLabel(label));
    }

    /**
     * 修改标签查询
     */
    @PreAuthorize("@ss.hasPermi('system:label:edit')")
    @Log(title = "标签查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Label label)
    {
        return toAjax(labelService.updateLabel(label));
    }

    /**
     * 删除标签查询
     */
    @PreAuthorize("@ss.hasPermi('system:label:remove')")
    @Log(title = "标签查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{labelIds}")
    public AjaxResult remove(@PathVariable Long[] labelIds)
    {
        return toAjax(labelService.deleteLabelByLabelIds(labelIds));
    }
}
